/**
 *	Copyright (c) 2009, SpLib.net
 * 	All rights reserved.
  	
 * 	Author:6spring
 * 	About:Base64编解码
*/

package SpLib.Tools
{
	import com.hurlant.util.Base64;
	import flash.utils.ByteArray;
	
	public class Base64
	{
		public function Base64()
		{
		}

		/**
		 * Base64编码，字符串
		*/
		public static function encode(data:String,charset:String):String
		{
			var bytes:ByteArray = new ByteArray();
			bytes.writeMultiByte(data,charset);
			return com.hurlant.util.Base64.encodeByteArray(bytes);
		}
		
		/**
		 * Base64编码，数组
		*/
		public static function encodeByteArray(bytes:ByteArray):String
		{
			return com.hurlant.util.Base64.encodeByteArray(bytes);
		}
		
		/**
		 * Base64解码，字符串
		*/
		public static function decode(str:String,charset:String):String
		{
			var bytes:ByteArray = com.hurlant.util.Base64.decodeToByteArray(str);
			return bytes.readMultiByte(bytes.length,charset);
		}
		
		/**
		 * Base64解码，数组
		*/
		public static function decodeByteArray(str:String):ByteArray
		{
			return com.hurlant.util.Base64.decodeToByteArray(str);
		}
	}
}